﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace teach
{
    public partial class WordPanel : PanelBase
    {
        public WordPanel()
        {
            InitializeComponent();
        }

        public Button ButtonAnswer
        {
            get
            {
                return btnNext;
            }
        }


        /// <summary>
        /// Set the operation question running
        /// </summary>
        /// <param name="question"></param>
        public override void SetQuestion(Question question)
        {
            Reset();
            m_answered = false;
            m_currentQuestion = question;
            txtAnswer.Text = "";
            string imgPath = Path.Combine(m_additionalResourcePath, question.Properties["image"]);
            pctStatus.Image = Bitmap.FromFile(imgPath);
            pctStatus.Refresh();

            this.timeoutMeter.Interval = question.Timeout;
            this.timeoutMeter.Enabled = true;

            txtAnswer.Focus();
        }

        public override Control GetAnswerControl()
        {
            return txtAnswer;
        }

        public override void SetStatusImage(bool success, Image image)
        {
            pctStatus.Image = image;
            pctStatus.Visible = true;
            pctStatus.Refresh();
            txtAnswer.ReadOnly = true;
            if (success)
            {
                txtAnswer.BackColor = Color.LightBlue;
            }
            else
            {
                txtAnswer.BackColor = Color.Red;
                txtAnswer.Text = m_currentQuestion.Answer.ToString();
            }
        }

        private void Reset()
        {
            pctStatus.Image = null;
            pctStatus.Refresh();
            txtAnswer.ReadOnly = false;
            txtAnswer.ForeColor = Color.Black;
            txtAnswer.BackColor = Color.White;
            txtAnswer.Text = "";
            btnNext.Text = "RÉPONSE";
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            m_answered = !m_answered;
            this.timeoutMeter.Enabled = false;
            if (m_answered)
            {
                base.RaiseAnswer(txtAnswer.Text);
                btnNext.Text = "Prochain";
            }
            else
            {
                Reset();
                base.RaiseNextClicked();
            }
        }

        private void btnSuggested_Click(object sender, EventArgs e)
        {

        }

        private void pctStatus_Click(object sender, EventArgs e)
        {

        }
    }
}
